$(function() {
    $(".loadingMarsk").css({
        "width":window.screen.availWidth,
        "height":window.screen.availHeight,
    });
    var token = localStorage.token;
    if(!token) {
        location.href = "../loginAndReg/login.html";
        return false;
    }
    new FastClick(document.body);
    function loadArea(pid) {
        $.ajax({
            type: "get",
            url: domain.test + "/getssx",
            // url: domain.online + "/region/list",
            data:{
                pid:pid
            },
            beforeSend: function(xhr) {
                flag = true;
                $(".loadingMarsk").css("display","block");
                xhr.setRequestHeader("token", token);
            },
            success: function (response) {
                if(response.data.rtnCode===200) {
                // if(response.rtnCode===200) {
                    var areaList = response.data.data;
                    // var areaList = response.data;
                    if(areaList.length===0) {
                        localStorage.area = area;
                        localStorage.areaId = areaId;
                        history.back();
                        return false;
                    }
                    $(".areaList").html(template("areaList",{areaList:areaList}));
                    $(".loadingMarsk").css("display","none");
                    flag = false;
                }
            }
        });
    }
    loadArea("");
    var area = "";
    var areaId = "";
    var flag = false;
    $(".areaList").on("click",".areaItem",function(){
        if(flag) return false;
        area += $(this).attr("data-name") + " ";
        areaId += $(this).attr("data-pid") + " ";
        var pid = parseFloat($(this).attr("data-pid"));
        loadArea(pid);
    });
});